package xyz.csmcool.imserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author 什锦
 * @Package xyz.csmcool.imchat.config
 * @since 2022/8/14 0:35
 */
@SpringBootConfiguration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private HttpAuthHandler httpAuthHandler;
    @Autowired
    private MyInterceptor myInterceptor;
    @Autowired
    private PrivateChatHandler privateChatHandler;
    @Autowired
    private PrivateChatInterceptor privateChatInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry
                .addHandler(httpAuthHandler, "/server/room-chat")
                .addInterceptors(myInterceptor)
                .setAllowedOrigins("*");

        registry.addHandler(privateChatHandler,"/server/private-chat")
                .addInterceptors(privateChatInterceptor)
                .setAllowedOrigins("*");
    }
}
